﻿#include "TrollBomber.h"
#include "../MapObject.h"
#include "../../../Shared/Enums.h"

using namespace Server::MirDatabase;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    TrollBomber::TrollBomber(MonsterInfo *info) : AxeSkeleton(info)
    {
    }

    void TrollBomber::CompleteRangeAttack(std::vector<std::any> &data)
    {
        MapObject *target = std::any_cast<MapObject*>(data[0]);
        int damage = std::any_cast<int>(data[1]);
        DefenceType defence = std::any_cast<DefenceType>(data[2]);

        if (target == nullptr || !target->IsAttackTarget(this) || target->getCurrentMap() != getCurrentMap() || target->Node == nullptr)
        {
            return;
        }

        std::vector<MapObject*> targets = FindAllTargets(2, target->getCurrentLocation());

        if (targets.empty())
        {
            return;
        }

        for (int i = 0; i < targets.size(); i++)
        {
            targets[i]->Attacked(this, targets[i] == target ? damage : damage / 2, defence);
        }
    }
}
